<?php
namespace Dashboard\Controller;
class UserController extends BaseController{
    //用户基本信息
    public function index(){
        $a        = (int)(I("currpage"));//跳转页数
        $sou      = I('sou');
        $pagesize = 15;
        if($a != null){
            $currpage = $a;
        }else{
            $currpage = isset($_GET['currpage'])?$_GET['currpage']:1;
        }
        if($sou){
            $content = I('content');
            $totalpage = 1;
            $currpage  = 1;
            if($sou == 1){
                $list      = joinss("users","a.*,b.address as ads",array("a left join __ADDRESS__ b on a.user_id = b.id"),"a.name = {$content}","a.id desc");
            }
            if($sou == 2){
                $list      = joinss("users","a.*,b.address as ads",array("a left join __ADDRESS__ b on a.user_id = b.id"),"a.phone = {$content}","a.id desc");
            }
            if($sou == 3){
                $list      = joinss("users","a.*,b.address as ads",array("a left join __ADDRESS__ b on a.user_id = b.id"),"b.address = {$content}","a.id desc");
            }
        }else{
            $result = currpages("users","a.*,b.address as ads",array("a left join __ADDRESS__ b on a.id = b.user_id"),"","a.id desc",$pagesize,$currpage);
            $totalpage = $result['totalpage'];
            $list      = $result['list'];
            if($result['currpage']){
                $currpage = $result['currpage'];
            }
        }
        $this->assign("list",$list)->assign("currpage",$currpage)->assign("totalpage",$totalpage);
        $this->display();
    }
    public function form(){
        $id    = I('id');
        $users  = sel("users"," * ","id = {$id}");
        $this->assign("users",$users);
        $this->display();
    }
    //用户详细信息
    public function info(){
        $a        = (int)(I("currpage"));//跳转页数
        $sou      = I('sou');
        $pagesize = 10;
        if($a != null){
            $currpage = $a;
        }else{
            $currpage = isset($_GET['currpage'])?$_GET['currpage']:1;
        }
        if($sou){
            if($sou == 1){//姓名
                $content = I('content');
                $content = I('content');
                $list = sels("users","*","name like '%{$content}%'","id desc");
            }
            if($sou == 2){//电话
                $content = I('content');
                $list = sels("users","*","phone like '%{$content}%'","id desc");
            }
            if($sou == 3){//职业
                $content = I('content');
                $list = sels("users","*","vocation like '%{$content}%'","id desc");
            }
        }else{
            $result= currpages("users","","","","id asc",$pagesize,$currpage);
            $totalpage = $result['totalpage'];
            $list      = $result['list'];
            if($result['currpage']){
                $currpage = $result['currpage'];
            }
        }
        $this->assign("list",$list)->assign("currpage",$currpage)->assign("totalpage",$totalpage);
        $this->display();
    }
    //积分核销历史
    public function hostorys(){
        $a        = (int)(I("currpage"));//跳转页数
        $sou      = I('sou');
        $pagesize = 20;
        if($a != null){
            $currpage = $a;
        }else{
            $currpage = isset($_GET['currpage'])?$_GET['currpage']:1;
        }
        if($sou){
            $content = I('content');
            $totalpage = 1;
            $currpage  = 1;
            if($sou == 1){
                $list      = sels("admin","","name like '%{$content}%'","id desc");
            }
            if($sou == 2){
                $list      = sels("admin","","numbers like '%{$content}%'","id desc");
            }
        }else{
            $result = currpages("covers_hostory","a.*,b.name,b.numbers,c.headimgurl,c.nickname,c.phone,c.name as user_name",array("a left join __ADMIN__ b on a.admin_id = b.id","left join __USERS__ c on a.user_id = c.id"),"","a.id desc",$pagesize,$currpage);
            $totalpage = $result['totalpage'];
            $list      = $result['list'];
            if($result['currpage']){
                $currpage = $result['currpage'];
            }
        }
        $this->assign("list",$list)->assign("currpage",$currpage)->assign("totalpage",$totalpage);
        $this->display();
    }
    public function vip_info(){
        $a        = (int)(I("currpage"));//跳转页数
        $sou      = I('sou');
        $pagesize = 15;
        if($a != null){
            $currpage = $a;
        }else{
            $currpage = isset($_GET['currpage'])?$_GET['currpage']:1;
        }
        //参数
        $where = "a.vip_type != 0";
        $table = "users";
        $filed = "a.xian_nums,a.create_at,a.vip_type,a.end_at,a.id,b.name,b.nick_name,b.sex,b.phone,b.avatar,b.img,a.flowers,a.covers,a.cha_nums,b.age,c.tags,d.name as vip_name";
        $join  = array("a left join __USERS_JIINFO__ b on a.id = b.user_id","left join __VIPS__ c on a.vip_type = c.id","left join __VIP_TYPE__ d on c.vip_type = d.id");
        if($sou){
            $content = I('content');
            $totalpage = 1;
            $currpage  = 1;
            if($sou == 1){
                $list      = joinss($table,$filed,$join,"{$where} and a.name = {$content}","a.id desc");
            }
            if($sou == 2){
                $list      = joinss($table,$filed,$join,"{$where} and a.phone = {$content}","a.id desc");
            }
            if($sou == 3){
                $list      = joinss($table,$filed,$join,"{$where} and b.address = {$content}","a.id desc");
            }
        }else{
            $result = currpages($table,$filed,$join,$where,"a.id desc",$pagesize,$currpage);
            $totalpage = $result['totalpage'];
            $list      = $result['list'];
            if($result['currpage']){
                $currpage = $result['currpage'];
            }
        }
        if($list){
            foreach ($list as $k=>$v){
                $age              = strtotime($v['age']);
                $list[$k]['ages'] = ages($age);
                $list[$k]['img']  = explode(",",$v['img']);
                if(!$v['flowers']){ $list[$k]['flowers']  = 0;}
                if(!$v['covers']){ $list[$k]['covers']  = 0;}
                if(!$v['cha_nums']){ $list[$k]['cha_nums']  = 0;}
                if($v['vip_type']){
                    if($v['end_at'] == -1){
                        $list[$k]['end_at']  = "无时间限制";
                    }else{
                        if($v['end_at'] < time()){
                            $list[$k]['end_at']  = "已过期";
                        }else{
                            $time = strtotime("+3 days");
                            if($v['end_at'] <= $time){
                                $list[$k]['end_at']  = date("Y-m-d H:i",$v['end_at'])."(即将过期)";
                            }else{
                                $list[$k]['end_at']  = date("Y-m-d H:i",$v['end_at']);
                            }
                        }
                    }
                }else{
                    $list[$k]['end_at']  = "";
                }
            }
        }
        $this->assign("list",$list)->assign("currpage",$currpage)->assign("totalpage",$totalpage);
        $this->display();
    }
    public function info_form(){
        $id        = I('id');
        $filed     = "a.xian_nums,a.id,a.nickname,a.headimgurl,a.vip_type,a.flowers,a.covers,a.cha_nums,
        b.id_card,b.avatar,b.img,b.address,b.age,b.name,b.nick_name,b.sex,b.wechat,b.qq,
        b.heights,b.weights,b.education,b.jobs,b.home,b.car,b.marriage,b.vacation,b.phone,b.child,b.moneys,b.place,
        b.smoking,b.drinking,b.marry_date,b.tags,
        c.address as ze_address,c.heights as ze_heights,c.weights as ze_weights,c.education as ze_education,
        c.marriage as ze_marriage,c.child as ze_child,c.moneys as ze_moneys,c.smoking as ze_smoking,c.drinking as ze_drinking,
        c.home as ze_home,c.car as ze_car";
        $list      = joins("users",$filed,array("a left join __USERS_JIINFO__ b on a.id = b.user_id","left join __USERS_ZEINFO__ c on a.id = c.user_id"),"a.id = {$id}");
        if($list['img']){
            $list['img'] = explode(",",$list['img']);
        }
        //vip信息
        $vip = sels("vips");
        foreach ($vip as $k=>$v){
            $c = sel("vip_type","name","id = {$v['vip_type']}");
            $vip[$k]['tags'] = $c['name']."-".$v['tags'];
        }
        if($list['vip_type']){
            $xian = sel("vips","tags,vip_type","id = {$list['vip_type']}");
            $v    = sel("vip_type","name","id = {$xian['vip_type']}");
            $v_name = "用户目前会员级别为：".$v['name']."-".$xian['tags'];
        }else{
            $v_name = "用户目前不是会员用户！";
        }
        $biao = hou_xian();

        //var_dump($biao);
        if($list['tags']){
            $ta = explode("/",$list['tags']);
            $tags_b   = sel("user_tags","content","id=1");
            $tags_g   = sel("user_tags","content","id=2");
            $tags_bs   = explode("/",$tags_b['content']);
            $tags_gs   = explode("/",$tags_g['content']);
            $tagss = array_merge($tags_bs,$tags_gs);
            for ($i = 0;$i<count($tagss);$i++){
                if(in_array($tagss[$i],$ta)){
                    $tags[$i]['choose'] = true;
                }else{
                    $tags[$i]['choose'] = false;
                }
                $tags[$i]['name'] = $tagss[$i];
            }
            $list['tags'] = $tags;
        }
        if($list['vacation']){
            $vacations = explode(",",$list['vacation']);
            $week        = array("星期天","星期一","星期二","星期三","星期四","星期五","星期六");
            for ($i=0;$i<7;$i++){
                if($i== 0){
                    $times = time();
                    $we    = $week[date("w",$times)]."(".date("Y/m/d",$times).")";
                    if(in_array($we,$vacations)){
                        $vacation[$i]['choose'] = true;
                    }else{
                        $vacation[$i]['choose'] = false;
                    }
                    $vacation[$i]['week'] = $we;
                }else{
                    $times = strtotime(+$i.'day');
                    $we    = $week[date("w",$times)]."(".date("Y/m/d",$times).")";
                    if(in_array($we,$vacations)){
                        $vacation[$i]['choose'] = true;
                    }else{
                        $vacation[$i]['choose'] = false;
                    }
                    $vacation[$i]['week'] = $we;
                }
            }
            $list['vacation'] = $vacation;
        }
        $this->assign("list",$list)
            ->assign("vip",$vip)
            ->assign("v_name",$v_name)
            ->assign("biao",$biao);

        $this->display();
    }
    public function info_add(){
        $user_id = I('id');
        if($user_id){
            if(QUAN == 2){
                $flowers = I("flowers");
                if($flowers){
                    $f  = up_one("users", "id = {$user_id}",array("flowers"=>$flowers));
                }
                $coverss  = I("covers");
                if($coverss){
                    $c  = up_one("users", "id = {$user_id}",array("covers"=>$coverss));
                }
                $cha_numss  = I("cha_nums");
                if($cha_numss){
                    $cn  = up_one("users", "id = {$user_id}",array("cha_nums"=>$cha_numss));
                }
                $vip_type = I('vip_type');//用户vip信息
                if($vip_type){
                    $user = sel("users","covers,cha_nums","id = {$user_id}");
                    $vip  = sel("vips","","id = {$vip_type}");
                    //消费加积分
                    $covers_shu   = sel("covers_shu","nums_two");
                    $cover_m      = floor($vip['moneys'])*$covers_shu['nums_two'];
                    $u['covers'] = $user['covers'] + $cover_m;
                    //查询人数修改
                    $u['cha_nums'] = $user['cha_nums'] + $vip['look_people'];
                    $u['vip_type'] = $vip_type;

                    $u  = up_one("users", "id = {$user_id}",$u);//用户积分增加
                    $cs = "+" . $cover_m;
                    $co = ins("users_covers", array("user_id" => $user_id, "shi_id" => $vip_type,"type"=>5, "covers" => $cs, "create_at" => time()));
                    $a = 1;
                }
            }
            $xian_nums = I('xian_nums');
            if($xian_nums){
                $we  = up_one("users", "id = {$user_id}",array('xian_nums'=>$xian_nums));//用户线下活动次数修改
                $b   = 1;
            }
            $ji['place'] = I('place');
            $ji['address'] = I('address');
            $ji['age'] = I('age');
            $ji['name'] = I('name');
            $ji['id_card'] = I('id_card');
            $ji['nick_name'] = I('nick_name');
            $ji['sex'] = I('sex');
            $ji['phone'] = I('phone');
            $ji['heights'] = I('heights');
            $ji['weights'] = I('weights');
            $ji['education'] = I('education');
            $ji['jobs'] = I('jobs');
            $ji['moneys'] = I('moneys');
            $ji['home'] = I('home');
            $ji['car'] = I('car');
            $ji['marriage'] = I('marriage');
            $ji['child'] = I('child');
            $ji['smoking'] = I('smoking');
            $ji['drinking'] = I('drinking');
            $ji['marry_date'] = I('marry_date');
            $ji['wechat'] = I('wechat');
            $ji['qq'] = I('qq');
            $ji['nature'] = I('nature');

            $vacation       = I('vacation');
            if($vacation){
                $ji['vacation'] = implode(",",$vacation);
            }
            $tags           = I('tags');
            if($tags){
                $ji['tags'] =  implode("/",$tags);
            }
            $ze['address'] = I('ze_address');
            $ze['age'] = I('ze_age');
            $ze['heights'] = I('ze_heights');
            $ze['weights'] = I('ze_weights');
            $ze['education'] = I('ze_education');
            $ze['moneys'] = I('ze_moneys');
            $ze['home'] = I('ze_home');
            $ze['car'] = I('ze_car');
            $ze['marriage'] = I('ze_marriage');
            $ze['child'] = I('ze_child');
            $ze['smoking'] = I('ze_smoking');
            $ze['drinking'] = I('ze_drinking');
            //判断是否存在用户信息
            $ji_info = sel("users_jiinfo","id","user_id = {$user_id}");
            $ze_info = sel("users_zeinfo","id","user_id = {$user_id}");
            if($ji_info){
                $ji['up_at'] = time();
                $res_ji = up_one("users_jiinfo","id = {$ji_info['id']}",$ji);
            }else{
                $ji['user_id']   = $user_id;
                $ji['create_at'] = time();
                $res_ji = ins("users_jiinfo",$ji);
            }
            if($ze_info){
                $ze['up_at'] = time();
                $res_ze = up_one("users_zeinfo","id = {$ze_info['id']}",$ze);
            }else{
                $ze['user_id']   = $user_id;
                $ze['create_at'] = time();
                $res_ze = ins("users_zeinfo",$ze);
            }
            if($res_ji || $res_ze){
                $this->ajaxReturn(array("status"=>2));
            }else{
                if($a == 1 || $b == 1){
                    $this->ajaxReturn(array("status"=>2));
                }else{
                    $this->ajaxReturn(array("status"=>3));
                }
            }
        }else{
            $this->ajaxReturn(array("status"=>1));//用户信息获取不到
        }
    }
    public function infos(){
       /* $id        = I('id');
        $filed     = "a.id,a.nickname,a.headimgurl,
        b.id_card,b.avatar,b.img,b.address,b.age,b.name,b.nick_name,b.sex,b.wechat,b.qq,
        b.heights,b.weights,b.education,b.jobs,b.home,b.car,b.marriage,b.vacation,b.phone,b.child,b.moneys,b.place,
        b.smoking,b.drinking,b.marry_date,b.tags,b.xingqu,b.xingge,
        c.address as ze_address,c.heights as ze_heights,c.weights as ze_weights,c.education as ze_education,
        c.marriage as ze_marriage,c.child as ze_child,c.moneys as ze_moneys,c.smoking as ze_smoking,c.drinking as ze_drinking,
        c.home as ze_home,c.car as ze_car,c.xuanyan,c.leixing";
        $list      = joins("users",$filed,array("a left join __USERS_JIINFO__ b on a.id = b.user_id","left join __USERS_ZEINFO__ c on a.id = c.user_id"),"a.id = {$id}");
        if($list['img']){
            $list['img'] = explode(",",$list['img']);
        }
        $age              = strtotime($list['age']);
        $list['ages'] = ages($age);
        $biao = hou_xian();
        $this->assign("list",$list)->assign("biao",$biao);*/
        $this->display();
    }
    //用户反馈
    public function fan(){
        $a        = (int)(I("currpage"));//跳转页数
        $sou      = I('sou');
        $pagesize = 15;
        if($a != null){
            $currpage = $a;
        }else{
            $currpage = isset($_GET['currpage'])?$_GET['currpage']:1;
        }
        if($sou){
            $content = I('content');
            $totalpage = 1;
            $currpage  = 1;
            if($sou == 1){
                $list      = joinss("backs","a.*,b.nickname,b.headimgurl",
                    array("a left join __USERS__ b on a.user_id = b.id"),"b.name like '%{$content}%'","a.id desc");
            }
            if($sou == 2){
                $list      = joinss("backs","a.*,b.nickname,b.headimgurl",
                    array("a left join __USERS__ b on a.user_id = b.id"),"b.phone like '%{$content}%'","a.id desc");
            }
            if($sou == 3){
                $list      = joinss("backs","a.*,b.nickname,b.headimgurl",
                    array("a left join __USERS__ b on a.user_id = b.id"),"b.nickname like '%{$content}%'","a.id desc");
            }
        }else{
            $result = currpages("backs","a.*,b.nickname,b.headimgurl",
                array("a left join __USERS__ b on a.user_id = b.id"),"","a.id desc",$pagesize,$currpage);
            $totalpage = $result['totalpage'];
            $list      = $result['list'];
            if($result['currpage']){
                $currpage = $result['currpage'];
            }
        }
        $this->assign("list",$list)->assign("currpage",$currpage)->assign("totalpage",$totalpage);
        $this->display();
    }
    //用户标签
    public function tags(){
        $list      = sels("user_tags");
        $this->assign("list",$list);
        $this->display();
    }
    public function tags_form(){
        $id      = I('id');
        if($id != null){
            $lists       = sel("user_tags","",array("id"=>$id));
            $this->assign("list",$lists);
        }
        $this->display();
    }
    //添加/修改
    public function tags_add(){
        $id               = $_POST['id'];
        $data['content'] = I('content');
        if($id == null){
            $data['create_at'] = time();
            $result             = ins("user_tags",$data);
            if($result){
                $logs = logs("添加了用户标签信息");
                $this->success("添加成功",U('tags_form'));}
        }else{
            $data['up_at']     = time();
            $result = up_one("user_tags",array("id"=>$id),$data);
            if($result){
                $logs = logs("修改了用户标签信息");
                $this->success("修改成功",U('tags'));}else{$this->success("没有信息变更，修改失败");}
        }
    }
    //个人中心背景
    public function back_img(){
        $a = (int)($_POST["currpage"]);//跳转页数
        if($a != null){
            $currpage = $a;
        }else{
            $currpage = isset($_GET['currpage'])?$_GET['currpage']:1;
        }
        $totalpage = 0;//总页数
        $pagesize  = 10;//每页显示数
        //搜索
        $sou     = $_POST['sou'];
        $content = $_POST['keywords'];
        if($sou != null){ //标题
        }else{
            $arr       = currpage("users_backimg","","$pagesize","$currpage","id desc");
            $totalpage = $arr['totalpage'];
            $list      = $arr['list'];
        }
        $this->assign("list",$list)->assign("currpage",$currpage)->assign("totalpage",$totalpage);
        $this->display();
    }
    public function back_img_form(){
        $id      = I('id');
        if($id != null){
            $list = sel("users_backimg","",array("id"=>$id));
            $this->assign("list",$list);
        }
        $this->display();
    }
    public function back_img_add(){
        $id               = $_POST['id'];
        //处理图片
        if($_FILES['one']['name'] != null){
            $img = I('img');
            unlink($img);
            $info                   = $this->imgUpload("banner/");
            $savename               = $info['one']['savename'];
            $savepath               = $info['one']['savepath'];
            $data['img']            = "Data/".$savepath.$savename;
        }
        if($id == null){
            $data['create_at'] = time();
            $result = ins("users_backimg",$data);
            if($result){
                $logs = logs("添加了个人中心皮肤背景");
                $this->success("添加成功",U('back_img_form'));}
        }else{
            $data['up_at']     = time();
            $result = up_one("users_backimg",array("id"=>$id),$data);
            if($result){
                $logs = logs("修改了个人中心皮肤背景");
                $this->success("修改成功",U('back_img'));}else{$this->success("没有信息变更，修改失败");}
        }
    }
    //用户转借记录
    public function zhuan()
    {
        $a = (int)(I("currpage"));//跳转页数
        $sou = I('sou');
        $content = I('content');
        $pagesize = 10;
        if ($a != null) {
            $currpage = $a;
        } else {
            $currpage = isset($_GET['currpage']) ? $_GET['currpage'] : 1;
        }
        if ($sou && $content) {

            $totalpage = 1;
            $currpage = 1;
            if ($sou == 1) {
                $list = join_group("zhuan", "a.*,c.headimgurl,c.nickname,c.phone,c.name as user_name", array("a left join __USERS__ c on a.user_id = c.id"), "c.name like '%{$content}%'", "a.id desc", "", "a.user_id");
            }
            if ($sou == 2) {
                $list = join_group("zhuan", "a.*,c.headimgurl,c.nickname,c.phone,c.name as user_name", array("a left join __USERS__ c on a.user_id = c.id"), "c.phone ={$content}", "a.id desc", "", "a.user_id");
            }
            if ($sou == 3) {
                $list = join_group("zhuan", "a.*,c.headimgurl,c.nickname,c.phone,c.name as user_name", array("a left join __USERS__ c on a.user_id = c.id"), "c.nickname like '%{$content}%'", "a.id desc", "", "a.user_id");
            }

        } else {
            $result = currpages_group("zhuan", "a.*,c.headimgurl,c.nickname,c.phone,c.name as user_name", array("a left join __USERS__ c on a.user_id = c.id"), "", "a.id desc", $pagesize, $currpage, "a.user_id");
            $totalpage = $result['totalpage'];
            $list = $result['list'];
            if ($result['currpage']) {
                $currpage = $result['currpage'];
            }
        }
        foreach ($list as $k => $v) {
            $list[$k]['zhuan'] = zhuan($v['user_id']);
        }
        $this->assign("list", $list)->assign("currpage", $currpage)->assign("totalpage", $totalpage);
        $this->display();
    }
    //积分核销
    public function xiao(){
        $id     = I('id');
        $covers = I("covers");
        if($covers > 0){
            $user = sel("users","covers,nickname","id = {$id}");
            $c    = $user['covers']-$covers;
            $u    = up_one("users","id = {$id}",array("covers"=>$c));
            if($u){
                //存储
                $hos    = ins("covers_hostory",array("user_id"=>$id,"admin_id"=>$_SESSION['admin']['id'],"covers"=>$covers,"create_at"=>time()));
                //积分明细
                $cc      = "-".$covers;
                $cov     = ins("covers",array("user_id"=>$id,"covers"=>$cc,"type"=>4,"create_at"=>time()));
                //日志
                $content = "管理员：".$_SESSION['admin']['numbers']." 于 ".date("Y-m-d H:i:s",time())."为用户：{$user['nickname']},核销了{$covers}个积分。";
                $log     = ins("logs",array("content"=>$content,"admin_id"=>$_SESSION['admin']['id'],"create_at"=>time()));
                $this->ajaxReturn(3);
            }else{
                $this->ajaxReturn(2);
            }
        }else{
            $this->ajaxReturn(1);
        }
    }
    /**
     *
     * 导出Excel
     */
    public function exportExcel($expTitle,$expCellName,$expTableData){
        $xlsTitle = iconv('utf-8', 'gb2312', $expTitle);//文件名称
        $fileName = $_SESSION['account'].date('_YmdHis');//or $xlsTitle 文件名称可根据自己情况设定
        $cellNum = count($expCellName);
        $dataNum = count($expTableData);
        Vendor('Classes.PHPExcel');
        $objPHPExcel = new \PHPExcel();
        $cellName = array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','AA','AB','AC','AD','AE','AF','AG','AH','AI','AJ','AK','AL','AM','AN','AO','AP','AQ','AR','AS','AT','AU','AV','AW','AX','AY','AZ');

        $objPHPExcel->getActiveSheet(0)->mergeCells('A1:'.$cellName[$cellNum-1].'1');//合并单元格
        // $objPHPExcel->setActiveSheetIndex(0)->setCellValue('A1', $expTitle.'  Export time:'.date('Y-m-d H:i:s'));
        for($i=0;$i<$cellNum;$i++){
            $objPHPExcel->setActiveSheetIndex(0)->setCellValue($cellName[$i].'2', $expCellName[$i][1]);
        }
        // Miscellaneous glyphs, UTF-8
        for($i=0;$i<$dataNum;$i++){
            for($j=0;$j<$cellNum;$j++){
                $objPHPExcel->getActiveSheet(0)->setCellValue($cellName[$j].($i+3), $expTableData[$i][$expCellName[$j][0]]);
            }
        }

        header('pragma:public');
        header('Content-type:application/vnd.ms-excel;charset=utf-8;name="'.$xlsTitle.'.xls"');
        header("Content-Disposition:attachment;filename=$fileName.xls");//attachment新窗口打印inline本窗口打印
        $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
        //$objWriter = \PHPExcel_IOFactory::
        $objWriter->save('php://output');
        exit;
    }
    public function expusers(){//导出Excel
        $type = I("type");
        $xlsName  = "users";
        $xlsCell  = array(
            array('id','序列'),
            array('type','报考类别'),
            array('name','姓名'),
            array('phone','电话'),
            array('email','邮箱'),
            array('sex','性别'),
            array('age','年龄'),
            array('bi_ye','是否毕业'),
            array('school','学校'),
            array('address','地址'),
            array('up_at','修改时间'),
            array('create_at','创建时间')
        );
        $xlsModel = M('users');
        if($type == 50000){
            $xlsData  = $xlsModel->Field('id,type,name,phone,email,sex,age,bi_ye,school,address,up_at,create_at')->select();
        }else{
            $xlsData  = $xlsModel->Field('id,type,name,phone,email,sex,age,bi_ye,school,address,up_at,create_at')->where("type = {$type}")->select();
        }
        if($xlsData){
            foreach ($xlsData as $k => $v)
            {
                $xlsData[$k]['up_at']      = date("Y-m-d H:i:s",$v['up_at']);
                $xlsData[$k]['create_at'] = date("Y-m-d H:i:s",$v['create_at']);
                //报考类别
                $bao = sel("course_type","name",array("id"=>$v['type']));
                $xlsData[$k]['type']    = $bao['name'];
                if($v['sex'] == 0){
                    $xlsData[$k]['sex']    = "未知";
                }
                if($v['sex'] == 1){
                    $xlsData[$k]['sex']    = "男";
                }
                if($v['sex'] == 2){
                    $xlsData[$k]['sex']    = "未知";
                }
                if($v['bi_ye'] == 1){
                    $xlsData[$k]['bi_ye'] = "未毕业";
                }else{
                    $xlsData[$k]['bi_ye'] = "已毕业";
                }
            }
            $this->exportExcel($xlsName,$xlsCell,$xlsData);
        }else{
            $this->success("暂无该类别用户！");
        }
    }
}